/*
 * Assist word
 */

import Assist from 'constants/assist';
import { CALL_BOOK_API } from '../middlewares';

/**
 * 创建辅助词
 */
export function createAssist(data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Assist.CREATE, Assist.CREATE_SUCCESS, Assist.CREATE_FAIL],
      uri: '/course-api/a/assist-word',
      method: 'POST',
      body: data,
    },
  };
}

/**
 * 更新辅助词
 */
export function updateAssist(assistId: number, data: Record<string, any>) {
  return {
    assistId,
    [CALL_BOOK_API]: {
      types: [Assist.UPDATE, Assist.UPDATE_SUCCESS, Assist.UPDATE_FAIL],
      uri: `/course-api/a/assist-word/${assistId}`,
      method: 'PUT',
      body: data,
    },
  };
}

/**
 * 查询辅助词详情，返回辅助词所有数据
 * @param data AssistModal
 */
export function fetchAssistDetail(assistId: number) {
  return {
    assistId,
    [CALL_BOOK_API]: {
      types: [Assist.FETCH, Assist.FETCH_SUCCESS, Assist.FETCH_FAIL],
      uri: `/course-api/a/assist-word/${assistId}`,
      method: 'GET',
    },
  };
}

/**
 * 删除辅助词
 * @param assistId
 */
export function removeAssist(assistId: number) {
  return {
    assistId,
    [CALL_BOOK_API]: {
      types: [Assist.REMOVE, Assist.REMOVE_SUCCESS, Assist.REMOVE_FAIL],
      uri: `/course-api/a/assist-word/${assistId}`,
      method: 'DELETE',
    },
  };
}

/**
 * 查询辅助词列表
 * @param filters 学期查询过滤
 */
export function fetchAssistList(filters: Record<string, any> = {}) {
  return {
    filters,
    [CALL_BOOK_API]: {
      types: [Assist.FETCH_LIST, Assist.FETCH_LIST_SUCCESS, Assist.FETCH_LIST_FAIL],
      uri: '/course-api/a/assist-word',
      method: 'GET',
      body: filters,
    },
  };
}

/**
 * 查询已关联(绘本页)到Lesson的知识点列表
 * @param filters 学期查询过滤
 */
export function fetchLessonAssistList(lessonId: number, filters: Record<string, any> = {}) {
  return {
    filters,
    [CALL_BOOK_API]: {
      types: [Assist.FETCH_LIST, Assist.FETCH_LIST_SUCCESS, Assist.FETCH_LIST_FAIL],
      uri: `/course-api/a/lessons/${lessonId}/assist-word`,
      method: 'GET',
      body: filters,
    },
  };
}
